package com.zx.mes.rabbitmq.api.hyl.quickstart;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * 生产者
 * @author huayunlong
 * @date 2018-9-4
 */
public class Producer {
    public static void main(String[] args) throws IOException, TimeoutException {
        ///创建一个工厂连接,并进行配置
        ConnectionFactory factory = new ConnectionFactory();
        factory.setUsername("admin");
        factory.setPassword("123456");
        factory.setHost("10.30.90.136");
        factory.setVirtualHost("/");
        factory.setPort(5672);
        /// 由工厂连接获取一个连接
        Connection connection = factory.newConnection();
        /// 由连接创建一个channel通道
        Channel channel = connection.createChannel();
        /// 发送信息
        channel.basicPublish("","test.queue",null,"神出现在周末!".getBytes());
        /// 关闭相关连接
        channel.close();
        connection.close();
    }
}
